package com.nuoniu.sibanyun.mapper.check;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.bo.QualityCheckSourceDataBo;
import com.nuoniu.sibanyun.entity.bo.QualityCheckSourceDataDetailBo;
import com.nuoniu.sibanyun.entity.check.VQualityCheckMain;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 质检管理_主表 Mapper 接口
 * </p>
 *
 * @author 白强
 * @since 2021-07-14
 */
public interface VQualityCheckMainMapper extends BaseMapper<VQualityCheckMain> {


    @Select("select voucher_code from qu_check_main where company_id=#{companyId} and date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) order by create_date desc limit 1")
    String getNewestCode(Integer companyId, String dateStr);

    /**
     * 查询来源单据主表信息
     * @param tableName
     * @param companyId
     * @param currentAccountId
     * @param sourceVoucherId
     * @return
     */
    QualityCheckSourceDataBo getVoucherMainBoById(String tableName,Integer companyId,Integer currentAccountId,Integer sourceVoucherId);

    /**
     * 查询来源单据明细表信息
     * @param tableName
     * @param companyId
     * @param currentAccountId
     * @param sourceVoucherId
     * @return
     */
    List<QualityCheckSourceDataDetailBo> getVoucherDetailBoById(String tableName, Integer companyId, Integer currentAccountId, Integer sourceVoucherId);

    /**
     * 更新 来源单据 累计报送数量
     * @param tableName
     * @param qualityCheckSourceDataBo
     */
    void updateQualityCheckSourceDataBo(String tableName, @Param("bo")QualityCheckSourceDataBo qualityCheckSourceDataBo);

    /**
     * 更新 来源单据 明细 累计报送数量
     * @param tableName
     * @param companyId
     * @param accountId
     * @param list
     */
    void updateQualityCheckSourceDataDetailBo(String tableName, Integer companyId, Integer accountId,@Param("set")List<QualityCheckSourceDataDetailBo> list);

    /**
     * 获取 当前 质检 明细的 报送数量
     * @param detailId
     * @return
     */
    BigDecimal getLastBaseQuality(Integer detailId);

}
